package everydayGrade.t2;

import org.junit.jupiter.api.Test;
import tool.s;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @Author: Siantar
 * @Date: 2024-01-05-20:02
 * @Description: 1.0
 */
public class T1944 {
    public int[] canSeePersonsCount(int[] heights) {
        int n = heights.length;
        int[] res = new int[n];
        Deque<Integer> deque = new ArrayDeque<>();
        for (int i = n - 1; i >= 0; i--) {
            while (!deque.isEmpty() && deque.peek() < heights[i]) {
                deque.pop();
                res[i]++;
            }
            if (!deque.isEmpty()) res[i]++;
            deque.push(heights[i]);
        }
        return res;
    }

    @Test
    public void test() {
        s.print(canSeePersonsCount(new int[]{10, 6, 8, 5, 11, 9}));
    }
}
